﻿

namespace LxCFD
{
    public class PISOUnit : SIMPLEUnit
    {
        protected volatile int MaxPISOSteps = 1;
        public override void Solve_Steady()
        {
            //SIMPLE部分
            base.Solve_Steady();
            //PRIME部分
            for (int i1 = 0; i1 < MaxPISOSteps; i1++)
            {
                updateMomentMatrix();
                MultiThreads.RunCalTasks((taskIndex) =>
                {
                    foreach (var pc in PCors) { pc.CalDc_ADiagNotRelaxed(taskIndex); }
                });
                SolveExplicit(Us, Connects);
                SolveExplicit(Vs, Connects);
                SolveExplicit(Ws, Connects);

                updatePCors();
                solvePCors();
                //4.进行修正
                MultiThreads.RunCalTasks((taskIndex) =>
                {
                    foreach (var pc in PCors) { pc.ApplyPCorToUVWP_NoRelax(taskIndex); }
                });
                MultiThreads.RunCalTasks((taskIndex) =>
                {
                    foreach (var v in Vels) { v.CalMassImbalance(taskIndex); }
                });
                updatePressure();
            }
        }
        public override void Solve_ImplicitTransient()
        {
            base.Solve_ImplicitTransient();
            for (int i1 = 0; i1 < MaxPISOSteps; i1++)
            {
                updateMomentMatrix();
                MultiThreads.RunCalTasks((taskIndex) =>
                {
                    foreach (var v in Vels)
                    {
                        v.U.TransData.SetAb_ImplicitTrans(taskIndex);
                        v.V.TransData.SetAb_ImplicitTrans(taskIndex);
                        v.W.TransData.SetAb_ImplicitTrans(taskIndex);
                    }
                });
                MultiThreads.RunCalTasks((taskIndex) =>
                {
                    foreach (var pc in PCors) { pc.CalDc_ADiagNotRelaxed(taskIndex); }
                });
                SolveExplicit(Us, Connects);
                SolveExplicit(Vs, Connects);
                SolveExplicit(Ws, Connects);

                updatePCors();
                solvePCors();
                //4.进行修正
                MultiThreads.RunCalTasks((taskIndex) =>
                {
                    foreach (var pc in PCors) { pc.ApplyPCorToUVWP_NoRelax(taskIndex); }
                });
                MultiThreads.RunCalTasks((taskIndex) =>
                {
                    foreach (var v in Vels) { v.CalMassImbalance(taskIndex); }
                });
                updatePressure();
            }
        }
    }
}
// public SIMPLEBaseUnit TempStor { get; set; }
//public override void Clear()
//{
//    base.Clear();
//    TempStor = new SIMPLEBaseUnit();
//}